/*
 * @Author: 0x9DEFA478
 * @Date: 2021-09-16 18:53:05
 * @LastEditTime: 2022-07-10 15:16:05
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#include "I_W25Q_DualBank.h"
#include "IP_GPIO.h"




//IO定义

//SCK

#define pI_W25Q_DualBank_SCK_GPIOx                                GPIOB
#define vI_W25Q_DualBank_SCK_PinNum                               2


//Bank1

#define pI_W25Q_DualBank_BK1CS_GPIOx                              GPIOB
#define vI_W25Q_DualBank_BK1CS_PinNum                             6

#define pI_W25Q_DualBank_BK1IO0_GPIOx                             GPIOD
#define vI_W25Q_DualBank_BK1IO0_PinNum                            11

#define pI_W25Q_DualBank_BK1IO1_GPIOx                             GPIOD
#define vI_W25Q_DualBank_BK1IO1_PinNum                            12

#define pI_W25Q_DualBank_BK1IO2_GPIOx                             GPIOE
#define vI_W25Q_DualBank_BK1IO2_PinNum                            2

#define pI_W25Q_DualBank_BK1IO3_GPIOx                             GPIOD
#define vI_W25Q_DualBank_BK1IO3_PinNum                            13


//Bank2

//#define pI_W25Q_DualBank_BK2CS_GPIOx
//#define vI_W25Q_DualBank_BK2CS_PinNum

#define pI_W25Q_DualBank_BK2IO0_GPIOx                             GPIOE
#define vI_W25Q_DualBank_BK2IO0_PinNum                            7

#define pI_W25Q_DualBank_BK2IO1_GPIOx                             GPIOE
#define vI_W25Q_DualBank_BK2IO1_PinNum                            8

#define pI_W25Q_DualBank_BK2IO2_GPIOx                             GPIOE
#define vI_W25Q_DualBank_BK2IO2_PinNum                            9

#define pI_W25Q_DualBank_BK2IO3_GPIOx                             GPIOE
#define vI_W25Q_DualBank_BK2IO3_PinNum                            10




//设置输入输出
#define oI_W25Q_DualBank_BK1IO0_Mode_Input()    pI_W25Q_DualBank_BK1IO0_GPIOx->MODER&=(~(0x3U<<(vI_W25Q_DualBank_BK1IO0_PinNum*2)))
#define oI_W25Q_DualBank_BK1IO0_Mode_Output()     pI_W25Q_DualBank_BK1IO0_GPIOx->MODER|=(0x1U<<(vI_W25Q_DualBank_BK1IO0_PinNum*2))

#define oI_W25Q_DualBank_BK1IO1_Mode_Input()    pI_W25Q_DualBank_BK1IO1_GPIOx->MODER&=(~(0x3U<<(vI_W25Q_DualBank_BK1IO1_PinNum*2)))
#define oI_W25Q_DualBank_BK1IO1_Mode_Output()     pI_W25Q_DualBank_BK1IO1_GPIOx->MODER|=(0x1U<<(vI_W25Q_DualBank_BK1IO1_PinNum*2))

#define oI_W25Q_DualBank_BK1IO2_Mode_Input()    pI_W25Q_DualBank_BK1IO2_GPIOx->MODER&=(~(0x3U<<(vI_W25Q_DualBank_BK1IO2_PinNum*2)))
#define oI_W25Q_DualBank_BK1IO2_Mode_Output()     pI_W25Q_DualBank_BK1IO2_GPIOx->MODER|=(0x1U<<(vI_W25Q_DualBank_BK1IO2_PinNum*2))

#define oI_W25Q_DualBank_BK1IO3_Mode_Input()    pI_W25Q_DualBank_BK1IO3_GPIOx->MODER&=(~(0x3U<<(vI_W25Q_DualBank_BK1IO3_PinNum*2)))
#define oI_W25Q_DualBank_BK1IO3_Mode_Output()     pI_W25Q_DualBank_BK1IO3_GPIOx->MODER|=(0x1U<<(vI_W25Q_DualBank_BK1IO3_PinNum*2))

#define oI_W25Q_DualBank_BK2IO0_Mode_Input()    pI_W25Q_DualBank_BK2IO0_GPIOx->MODER&=(~(0x3U<<(vI_W25Q_DualBank_BK2IO0_PinNum*2)))
#define oI_W25Q_DualBank_BK2IO0_Mode_Output()     pI_W25Q_DualBank_BK2IO0_GPIOx->MODER|=(0x1U<<(vI_W25Q_DualBank_BK2IO0_PinNum*2))

#define oI_W25Q_DualBank_BK2IO1_Mode_Input()    pI_W25Q_DualBank_BK2IO1_GPIOx->MODER&=(~(0x3U<<(vI_W25Q_DualBank_BK2IO1_PinNum*2)))
#define oI_W25Q_DualBank_BK2IO1_Mode_Output()     pI_W25Q_DualBank_BK2IO1_GPIOx->MODER|=(0x1U<<(vI_W25Q_DualBank_BK2IO1_PinNum*2))

#define oI_W25Q_DualBank_BK2IO2_Mode_Input()    pI_W25Q_DualBank_BK2IO2_GPIOx->MODER&=(~(0x3U<<(vI_W25Q_DualBank_BK2IO2_PinNum*2)))
#define oI_W25Q_DualBank_BK2IO2_Mode_Output()     pI_W25Q_DualBank_BK2IO2_GPIOx->MODER|=(0x1U<<(vI_W25Q_DualBank_BK2IO2_PinNum*2))

#define oI_W25Q_DualBank_BK2IO3_Mode_Input()    pI_W25Q_DualBank_BK2IO3_GPIOx->MODER&=(~(0x3U<<(vI_W25Q_DualBank_BK2IO3_PinNum*2)))
#define oI_W25Q_DualBank_BK2IO3_Mode_Output()     pI_W25Q_DualBank_BK2IO3_GPIOx->MODER|=(0x1U<<(vI_W25Q_DualBank_BK2IO3_PinNum*2))


//置位 复位

#define oI_W25Q_DualBank_SCK_SetOutput_High()    oIP_GPIO_SetOutput_High(pI_W25Q_DualBank_SCK_GPIOx,vI_W25Q_DualBank_SCK_PinNum)
#define oI_W25Q_DualBank_SCK_SetOutput_Low()     oIP_GPIO_SetOutput_Low( pI_W25Q_DualBank_SCK_GPIOx,vI_W25Q_DualBank_SCK_PinNum)


#if defined(pI_W25Q_DualBank_BK1CS_GPIOx)&&defined(vI_W25Q_DualBank_BK1CS_PinNum)
#define oI_W25Q_DualBank_BK1CS_SetOutput_High()  oIP_GPIO_SetOutput_High(pI_W25Q_DualBank_BK1CS_GPIOx,vI_W25Q_DualBank_BK1CS_PinNum)
#define oI_W25Q_DualBank_BK1CS_SetOutput_Low()   oIP_GPIO_SetOutput_Low( pI_W25Q_DualBank_BK1CS_GPIOx,vI_W25Q_DualBank_BK1CS_PinNum)
#endif

#define oI_W25Q_DualBank_BK1IO0_SetOutput_High() oIP_GPIO_SetOutput_High(pI_W25Q_DualBank_BK1IO0_GPIOx,vI_W25Q_DualBank_BK1IO0_PinNum)
#define oI_W25Q_DualBank_BK1IO0_SetOutput_Low()  oIP_GPIO_SetOutput_Low( pI_W25Q_DualBank_BK1IO0_GPIOx,vI_W25Q_DualBank_BK1IO0_PinNum)

#define oI_W25Q_DualBank_BK1IO1_SetOutput_High() oIP_GPIO_SetOutput_High(pI_W25Q_DualBank_BK1IO1_GPIOx,vI_W25Q_DualBank_BK1IO1_PinNum)
#define oI_W25Q_DualBank_BK1IO1_SetOutput_Low()  oIP_GPIO_SetOutput_Low( pI_W25Q_DualBank_BK1IO1_GPIOx,vI_W25Q_DualBank_BK1IO1_PinNum)

#define oI_W25Q_DualBank_BK1IO2_SetOutput_High() oIP_GPIO_SetOutput_High(pI_W25Q_DualBank_BK1IO2_GPIOx,vI_W25Q_DualBank_BK1IO2_PinNum)
#define oI_W25Q_DualBank_BK1IO2_SetOutput_Low()  oIP_GPIO_SetOutput_Low( pI_W25Q_DualBank_BK1IO2_GPIOx,vI_W25Q_DualBank_BK1IO2_PinNum)

#define oI_W25Q_DualBank_BK1IO3_SetOutput_High() oIP_GPIO_SetOutput_High(pI_W25Q_DualBank_BK1IO3_GPIOx,vI_W25Q_DualBank_BK1IO3_PinNum)
#define oI_W25Q_DualBank_BK1IO3_SetOutput_Low()  oIP_GPIO_SetOutput_Low( pI_W25Q_DualBank_BK1IO3_GPIOx,vI_W25Q_DualBank_BK1IO3_PinNum)


#if defined(pI_W25Q_DualBank_BK2CS_GPIOx)&&defined(vI_W25Q_DualBank_BK2CS_PinNum)
#define oI_W25Q_DualBank_BK2CS_SetOutput_High()  oIP_GPIO_SetOutput_High(pI_W25Q_DualBank_BK2CS_GPIOx,vI_W25Q_DualBank_BK2CS_PinNum)
#define oI_W25Q_DualBank_BK2CS_SetOutput_Low()   oIP_GPIO_SetOutput_Low( pI_W25Q_DualBank_BK2CS_GPIOx,vI_W25Q_DualBank_BK2CS_PinNum)
#endif

#define oI_W25Q_DualBank_BK2IO0_SetOutput_High() oIP_GPIO_SetOutput_High(pI_W25Q_DualBank_BK2IO0_GPIOx,vI_W25Q_DualBank_BK2IO0_PinNum)
#define oI_W25Q_DualBank_BK2IO0_SetOutput_Low()  oIP_GPIO_SetOutput_Low( pI_W25Q_DualBank_BK2IO0_GPIOx,vI_W25Q_DualBank_BK2IO0_PinNum)

#define oI_W25Q_DualBank_BK2IO1_SetOutput_High() oIP_GPIO_SetOutput_High(pI_W25Q_DualBank_BK2IO1_GPIOx,vI_W25Q_DualBank_BK2IO1_PinNum)
#define oI_W25Q_DualBank_BK2IO1_SetOutput_Low()  oIP_GPIO_SetOutput_Low( pI_W25Q_DualBank_BK2IO1_GPIOx,vI_W25Q_DualBank_BK2IO1_PinNum)

#define oI_W25Q_DualBank_BK2IO2_SetOutput_High() oIP_GPIO_SetOutput_High(pI_W25Q_DualBank_BK2IO2_GPIOx,vI_W25Q_DualBank_BK2IO2_PinNum)
#define oI_W25Q_DualBank_BK2IO2_SetOutput_Low()  oIP_GPIO_SetOutput_Low( pI_W25Q_DualBank_BK2IO2_GPIOx,vI_W25Q_DualBank_BK2IO2_PinNum)

#define oI_W25Q_DualBank_BK2IO3_SetOutput_High() oIP_GPIO_SetOutput_High(pI_W25Q_DualBank_BK2IO3_GPIOx,vI_W25Q_DualBank_BK2IO3_PinNum)
#define oI_W25Q_DualBank_BK2IO3_SetOutput_Low()  oIP_GPIO_SetOutput_Low( pI_W25Q_DualBank_BK2IO3_GPIOx,vI_W25Q_DualBank_BK2IO3_PinNum)


#define oI_W25Q_DualBank_BKIO_SetOutput_High()  oI_W25Q_DualBank_BK1IO0_SetOutput_High();\
                                                oI_W25Q_DualBank_BK1IO1_SetOutput_High();\
                                                oI_W25Q_DualBank_BK1IO2_SetOutput_High();\
                                                oI_W25Q_DualBank_BK1IO3_SetOutput_High();\
                                                oI_W25Q_DualBank_BK2IO0_SetOutput_High();\
                                                oI_W25Q_DualBank_BK2IO1_SetOutput_High();\
                                                oI_W25Q_DualBank_BK2IO2_SetOutput_High();\
                                                oI_W25Q_DualBank_BK2IO3_SetOutput_High()
#define oI_W25Q_DualBank_BKIO_SetOutput_Low()   oI_W25Q_DualBank_BK1IO0_SetOutput_Low();\
                                                oI_W25Q_DualBank_BK1IO1_SetOutput_Low();\
                                                oI_W25Q_DualBank_BK1IO2_SetOutput_Low();\
                                                oI_W25Q_DualBank_BK1IO3_SetOutput_Low();\
                                                oI_W25Q_DualBank_BK2IO0_SetOutput_Low();\
                                                oI_W25Q_DualBank_BK2IO1_SetOutput_Low();\
                                                oI_W25Q_DualBank_BK2IO2_SetOutput_Low();\
                                                oI_W25Q_DualBank_BK2IO3_SetOutput_Low()

#if defined(pI_W25Q_DualBank_BK1CS_GPIOx)&&defined(vI_W25Q_DualBank_BK1CS_PinNum)&&defined(pI_W25Q_DualBank_BK2CS_GPIOx)&&defined(vI_W25Q_DualBank_BK2CS_PinNum)

#define oI_W25Q_DualBank_BKCS_SetOutput_High()    oI_W25Q_DualBank_BK1CS_SetOutput_High();oI_W25Q_DualBank_BK2CS_SetOutput_High()
#define oI_W25Q_DualBank_BKCS_SetOutput_Low()     oI_W25Q_DualBank_BK1CS_SetOutput_Low();_I_W25Q_DualBank_BK2CS_SetOutput_Low()

#else 

#if defined(pI_W25Q_DualBank_BK1CS_GPIOx)&&defined(vI_W25Q_DualBank_BK1CS_PinNum)

#define oI_W25Q_DualBank_BKCS_SetOutput_High()    oI_W25Q_DualBank_BK1CS_SetOutput_High()
#define oI_W25Q_DualBank_BKCS_SetOutput_Low()     oI_W25Q_DualBank_BK1CS_SetOutput_Low()

#elif defined(pI_W25Q_DualBank_BK2CS_GPIOx)&&defined(vI_W25Q_DualBank_BK2CS_PinNum)

#define oI_W25Q_DualBank_BKCS_SetOutput_High()    oI_W25Q_DualBank_BK2CS_SetOutput_High()
#define oI_W25Q_DualBank_BKCS_SetOutput_Low()     oI_W25Q_DualBank_BK2CS_SetOutput_Low()

#endif

#endif


#define oI_W25Q_DualBank_BKIO_OUT()   oI_W25Q_DualBank_BK1IO0_Mode_Output();\
                                      oI_W25Q_DualBank_BK1IO1_Mode_Output();\
                                      oI_W25Q_DualBank_BK1IO2_Mode_Output();\
                                      oI_W25Q_DualBank_BK1IO3_Mode_Output();\
                                      oI_W25Q_DualBank_BK2IO0_Mode_Output();\
                                      oI_W25Q_DualBank_BK2IO1_Mode_Output();\
                                      oI_W25Q_DualBank_BK2IO2_Mode_Output();\
                                      oI_W25Q_DualBank_BK2IO3_Mode_Output()
#define oI_W25Q_DualBank_BKIO_IN()    oI_W25Q_DualBank_BK1IO0_Mode_Input();\
                                      oI_W25Q_DualBank_BK1IO1_Mode_Input();\
                                      oI_W25Q_DualBank_BK1IO2_Mode_Input();\
                                      oI_W25Q_DualBank_BK1IO3_Mode_Input();\
                                      oI_W25Q_DualBank_BK2IO0_Mode_Input();\
                                      oI_W25Q_DualBank_BK2IO1_Mode_Input();\
                                      oI_W25Q_DualBank_BK2IO2_Mode_Input();\
                                      oI_W25Q_DualBank_BK2IO3_Mode_Input()



//读取输入

#define oI_W25Q_DualBank_BK1IO0_GetInputBit()    oIP_GPIO_GetInputBit(pI_W25Q_DualBank_BK1IO0_GPIOx,vI_W25Q_DualBank_BK1IO0_PinNum)
#define oI_W25Q_DualBank_BK1IO1_GetInputBit()    oIP_GPIO_GetInputBit(pI_W25Q_DualBank_BK1IO1_GPIOx,vI_W25Q_DualBank_BK1IO1_PinNum)
#define oI_W25Q_DualBank_BK1IO2_GetInputBit()    oIP_GPIO_GetInputBit(pI_W25Q_DualBank_BK1IO2_GPIOx,vI_W25Q_DualBank_BK1IO2_PinNum)
#define oI_W25Q_DualBank_BK1IO3_GetInputBit()    oIP_GPIO_GetInputBit(pI_W25Q_DualBank_BK1IO3_GPIOx,vI_W25Q_DualBank_BK1IO3_PinNum)

#define oI_W25Q_DualBank_BK2IO0_GetInputBit()    oIP_GPIO_GetInputBit(pI_W25Q_DualBank_BK2IO0_GPIOx,vI_W25Q_DualBank_BK2IO0_PinNum)
#define oI_W25Q_DualBank_BK2IO1_GetInputBit()    oIP_GPIO_GetInputBit(pI_W25Q_DualBank_BK2IO1_GPIOx,vI_W25Q_DualBank_BK2IO1_PinNum)
#define oI_W25Q_DualBank_BK2IO2_GetInputBit()    oIP_GPIO_GetInputBit(pI_W25Q_DualBank_BK2IO2_GPIOx,vI_W25Q_DualBank_BK2IO2_PinNum)
#define oI_W25Q_DualBank_BK2IO3_GetInputBit()    oIP_GPIO_GetInputBit(pI_W25Q_DualBank_BK2IO3_GPIOx,vI_W25Q_DualBank_BK2IO3_PinNum)




static void SetIO_1Line(void);

static void IO_Init(){

  if((RCC->AHB3ENR&RCC_AHB3ENR_QSPIEN)!=0U){
    if((QUADSPI->CR&QUADSPI_CR_EN)!=0U){
      QUADSPI->CR=0;
    }
  }
  
  RCC->AHB4ENR|=RCC_AHB4ENR_GPIOBEN|RCC_AHB4ENR_GPIODEN|RCC_AHB4ENR_GPIOEEN;


  oI_W25Q_DualBank_SCK_SetOutput_Low();
  oI_W25Q_DualBank_BKCS_SetOutput_High();

  oIP_GPIO_Config(pI_W25Q_DualBank_SCK_GPIOx,vI_W25Q_DualBank_SCK_PinNum,vIP_GPIO_Mode_OUT,vIP_GPIO_OutType_PP,vIP_GPIO_Speed_HIGH,vIP_GPIO_PuPd_NP);

#if defined(pI_W25Q_DualBank_BK1CS_GPIOx)&&defined(vI_W25Q_DualBank_BK1CS_PinNum)
  oIP_GPIO_Config(pI_W25Q_DualBank_BK1CS_GPIOx,vI_W25Q_DualBank_BK1CS_PinNum,vIP_GPIO_Mode_OUT,vIP_GPIO_OutType_PP,vIP_GPIO_Speed_HIGH,vIP_GPIO_PuPd_NP);
#endif
  oIP_GPIO_Config(pI_W25Q_DualBank_BK1IO0_GPIOx,vI_W25Q_DualBank_BK1IO0_PinNum,vIP_GPIO_Mode_IN,vIP_GPIO_OutType_PP,vIP_GPIO_Speed_HIGH,vIP_GPIO_PuPd_NP);
  oIP_GPIO_Config(pI_W25Q_DualBank_BK1IO1_GPIOx,vI_W25Q_DualBank_BK1IO1_PinNum,vIP_GPIO_Mode_IN,vIP_GPIO_OutType_PP,vIP_GPIO_Speed_HIGH,vIP_GPIO_PuPd_NP);
  oIP_GPIO_Config(pI_W25Q_DualBank_BK1IO2_GPIOx,vI_W25Q_DualBank_BK1IO2_PinNum,vIP_GPIO_Mode_IN,vIP_GPIO_OutType_PP,vIP_GPIO_Speed_HIGH,vIP_GPIO_PuPd_NP);
  oIP_GPIO_Config(pI_W25Q_DualBank_BK1IO3_GPIOx,vI_W25Q_DualBank_BK1IO3_PinNum,vIP_GPIO_Mode_IN,vIP_GPIO_OutType_PP,vIP_GPIO_Speed_HIGH,vIP_GPIO_PuPd_NP);

#if defined(pI_W25Q_DualBank_BK2CS_GPIOx)&&defined(vI_W25Q_DualBank_BK2CS_PinNum)
  oIP_GPIO_Config(pI_W25Q_DualBank_BK1CS_GPIOx,vI_W25Q_DualBank_BK2CS_PinNum,vIP_GPIO_Mode_OUT,vIP_GPIO_OutType_PP,vIP_GPIO_Speed_HIGH,vIP_GPIO_PuPd_NP);
#endif
  oIP_GPIO_Config(pI_W25Q_DualBank_BK2IO0_GPIOx,vI_W25Q_DualBank_BK2IO0_PinNum,vIP_GPIO_Mode_IN,vIP_GPIO_OutType_PP,vIP_GPIO_Speed_HIGH,vIP_GPIO_PuPd_NP);
  oIP_GPIO_Config(pI_W25Q_DualBank_BK2IO1_GPIOx,vI_W25Q_DualBank_BK2IO1_PinNum,vIP_GPIO_Mode_IN,vIP_GPIO_OutType_PP,vIP_GPIO_Speed_HIGH,vIP_GPIO_PuPd_NP);
  oIP_GPIO_Config(pI_W25Q_DualBank_BK2IO2_GPIOx,vI_W25Q_DualBank_BK2IO2_PinNum,vIP_GPIO_Mode_IN,vIP_GPIO_OutType_PP,vIP_GPIO_Speed_HIGH,vIP_GPIO_PuPd_NP);
  oIP_GPIO_Config(pI_W25Q_DualBank_BK2IO3_GPIOx,vI_W25Q_DualBank_BK2IO3_PinNum,vIP_GPIO_Mode_IN,vIP_GPIO_OutType_PP,vIP_GPIO_Speed_HIGH,vIP_GPIO_PuPd_NP);


  SetIO_1Line();

}

static void delay_us(unsigned int timeUs){

  unsigned int t,nowT;
  unsigned int lastT;
  unsigned int cenT;
  unsigned int SysReLoad;

  SysReLoad=SysTick->LOAD;
  lastT=SysTick->VAL;
  t=timeUs*(480000000/1000000U);
  cenT=0;
  for(;;){
    nowT=SysTick->VAL;
    if(nowT!=lastT){
      if(nowT<lastT){
        cenT+=lastT-nowT;
      }else{
        cenT+=SysReLoad-nowT+lastT;
      }
      if(cenT>=t){
        break;
      }
      lastT=nowT;
    }
  }
}

//延时10ns以上的时间 用于保证CS的高电平时间
static void Delay10ns(){
  delay_us(1);
}

//延时50ns以上的时间 用于保证CS的高电平时间
static void Delay50ns(){

  delay_us(1);
}

static void SetIO_1Line(){

  oI_W25Q_DualBank_BK1IO2_SetOutput_High();
  oI_W25Q_DualBank_BK2IO2_SetOutput_High();
  oI_W25Q_DualBank_BK1IO3_SetOutput_High();
  oI_W25Q_DualBank_BK2IO3_SetOutput_High();

  oI_W25Q_DualBank_BK1IO0_Mode_Output();
  oI_W25Q_DualBank_BK1IO1_Mode_Input();
  oI_W25Q_DualBank_BK1IO2_Mode_Output();
  oI_W25Q_DualBank_BK1IO3_Mode_Output();

  oI_W25Q_DualBank_BK2IO0_Mode_Output();
  oI_W25Q_DualBank_BK2IO1_Mode_Input();
  oI_W25Q_DualBank_BK2IO2_Mode_Output();
  oI_W25Q_DualBank_BK2IO3_Mode_Output();
}

//单线传输数据
static unsigned short TxRxByte(unsigned short TxData){
  unsigned int tx1,tx2,rx1,rx2;
  unsigned int Mask;


  tx1=0x000000FFU&TxData;
  tx2=0x000000FFU&(TxData>>8);


  Mask=0x80U;
  rx1=0U;
  rx2=0U;
  while(Mask){
    
    if((Mask&tx1)!=0U){
      oI_W25Q_DualBank_BK1IO0_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK1IO0_SetOutput_Low();
    }

    if((Mask&tx2)!=0U){
      oI_W25Q_DualBank_BK2IO0_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK2IO0_SetOutput_Low();
    }

    oI_W25Q_DualBank_SCK_SetOutput_High();
    
    rx1<<=1;
    rx2<<=1;
    if(oI_W25Q_DualBank_BK1IO1_GetInputBit()!=0U){
      rx1|=0x01U;
    }else{
      rx1&=0xFEU;
    }
    if(oI_W25Q_DualBank_BK2IO1_GetInputBit()!=0U){
      rx2|=0x01U;
    }else{
      rx2&=0xFEU;
    }

    Mask>>=1;
    oI_W25Q_DualBank_SCK_SetOutput_Low();

  }

  return rx1|(rx2<<8);
}

//四线发送字节
void Tx_4Line(unsigned char* Src,unsigned int Length){
  unsigned char Temp1,Temp2;

  if((Length&0x00000001U)!=0U){//保证Len为2的倍数
    Length+=1U;
  }

  Temp1=Src[0];
  Temp2=Src[1];
  Src=&Src[2];

  while(Length>0){
    Length-=2;

    //发送一个字节

    if((0x80U&Temp1)!=0U){
      oI_W25Q_DualBank_BK1IO3_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK1IO3_SetOutput_Low();
    }
    if((0x40U&Temp1)!=0U){
      oI_W25Q_DualBank_BK1IO2_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK1IO2_SetOutput_Low();
    }
    if((0x20U&Temp1)!=0U){
      oI_W25Q_DualBank_BK1IO1_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK1IO1_SetOutput_Low();
    }
    if((0x10U&Temp1)!=0U){
      oI_W25Q_DualBank_BK1IO0_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK1IO0_SetOutput_Low();
    }

    if((0x80U&Temp2)!=0U){
      oI_W25Q_DualBank_BK2IO3_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK2IO3_SetOutput_Low();
    }
    if((0x40U&Temp2)!=0U){
      oI_W25Q_DualBank_BK2IO2_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK2IO2_SetOutput_Low();
    }
    if((0x20U&Temp2)!=0U){
      oI_W25Q_DualBank_BK2IO1_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK2IO1_SetOutput_Low();
    }
    if((0x10U&Temp2)!=0U){
      oI_W25Q_DualBank_BK2IO0_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK2IO0_SetOutput_Low();
    }

    oI_W25Q_DualBank_SCK_SetOutput_High();
    Temp1<<=4;
    Temp2<<=4;
    oI_W25Q_DualBank_SCK_SetOutput_Low();

    //发送一个字节

    if((0x80U&Temp1)!=0U){
      oI_W25Q_DualBank_BK1IO3_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK1IO3_SetOutput_Low();
    }
    if((0x40U&Temp1)!=0U){
      oI_W25Q_DualBank_BK1IO2_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK1IO2_SetOutput_Low();
    }
    if((0x20U&Temp1)!=0U){
      oI_W25Q_DualBank_BK1IO1_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK1IO1_SetOutput_Low();
    }
    if((0x10U&Temp1)!=0U){
      oI_W25Q_DualBank_BK1IO0_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK1IO0_SetOutput_Low();
    }

    if((0x80U&Temp2)!=0U){
      oI_W25Q_DualBank_BK2IO3_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK2IO3_SetOutput_Low();
    }
    if((0x40U&Temp2)!=0U){
      oI_W25Q_DualBank_BK2IO2_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK2IO2_SetOutput_Low();
    }
    if((0x20U&Temp2)!=0U){
      oI_W25Q_DualBank_BK2IO1_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK2IO1_SetOutput_Low();
    }
    if((0x10U&Temp2)!=0U){
      oI_W25Q_DualBank_BK2IO0_SetOutput_High();
    }else{
      oI_W25Q_DualBank_BK2IO0_SetOutput_Low();
    }

    //更换到下一组数据
    oI_W25Q_DualBank_SCK_SetOutput_High();
    Temp1=Src[0];
    Temp2=Src[1];
    Src=&Src[2];
    oI_W25Q_DualBank_SCK_SetOutput_Low();
  }

}

//四线接收字节
void Rx_4Line(unsigned char* Dst,unsigned int Length){
  unsigned char Temp1,Temp2;

  if((Length&0x00000001U)!=0U){//保证Len为2的倍数
    Length+=1U;
  }

  while(Length>0){
    Length-=2U;

    Temp1=0U;
    Temp2=0U;

    oI_W25Q_DualBank_SCK_SetOutput_High();

    if(oI_W25Q_DualBank_BK1IO3_GetInputBit()!=0U){
      Temp1|=0x08U;
    }else{
      Temp1&=0xF7U;
    }
    if(oI_W25Q_DualBank_BK1IO2_GetInputBit()!=0U){
      Temp1|=0x04U;
    }else{
      Temp1&=0xFBU;
    }
    if(oI_W25Q_DualBank_BK1IO1_GetInputBit()!=0U){
      Temp1|=0x02U;
    }else{
      Temp1&=0xFDU;
    }
    if(oI_W25Q_DualBank_BK1IO0_GetInputBit()!=0U){
      Temp1|=0x01U;
    }else{
      Temp1&=0xFEU;
    }

    if(oI_W25Q_DualBank_BK2IO3_GetInputBit()!=0U){
      Temp2|=0x08U;
    }else{
      Temp2&=0xF7U;
    }if(oI_W25Q_DualBank_BK2IO2_GetInputBit()!=0U){
      Temp2|=0x04U;
    }
    else{
      Temp2&=0xFBU;
    }if(oI_W25Q_DualBank_BK2IO1_GetInputBit()!=0U){
      Temp2|=0x02U;
    }
    else{
      Temp2&=0xFDU;
    }if(oI_W25Q_DualBank_BK2IO0_GetInputBit()!=0U){
      Temp2|=0x01U;
    }else{
      Temp2&=0xFEU;
    }

    oI_W25Q_DualBank_SCK_SetOutput_Low();
    Temp1<<=4;
    Temp2<<=4;
    oI_W25Q_DualBank_SCK_SetOutput_High();

    if(oI_W25Q_DualBank_BK1IO3_GetInputBit()!=0U){
      Temp1|=0x08U;
    }else{
      Temp1&=0xF7U;
    }
    if(oI_W25Q_DualBank_BK1IO2_GetInputBit()!=0U){
      Temp1|=0x04U;
    }else{
      Temp1&=0xFBU;
    }
    if(oI_W25Q_DualBank_BK1IO1_GetInputBit()!=0U){
      Temp1|=0x02U;
    }else{
      Temp1&=0xFDU;
    }
    if(oI_W25Q_DualBank_BK1IO0_GetInputBit()!=0U){
      Temp1|=0x01U;
    }else{
      Temp1&=0xFEU;
    }

    if(oI_W25Q_DualBank_BK2IO3_GetInputBit()!=0U){
      Temp2|=0x08U;
    }else{
      Temp2&=0xF7U;
    }if(oI_W25Q_DualBank_BK2IO2_GetInputBit()!=0U){
      Temp2|=0x04U;
    }
    else{
      Temp2&=0xFBU;
    }if(oI_W25Q_DualBank_BK2IO1_GetInputBit()!=0U){
      Temp2|=0x02U;
    }
    else{
      Temp2&=0xFDU;
    }if(oI_W25Q_DualBank_BK2IO0_GetInputBit()!=0U){
      Temp2|=0x01U;
    }else{
      Temp2&=0xFEU;
    }

    oI_W25Q_DualBank_SCK_SetOutput_Low();

    Dst[0]=Temp1;
    Dst[1]=Temp2;
    Dst=&Dst[2];
  }

}




//==============================================================================================================================
//
//       w25q部分
//
//==============================================================================================================================

//状态掩码
//S0~S7
#define vI_W25Q_Status_BUSY                                       0x01U
#define vI_W25Q_Status_WEL                                        0x02U
#define vI_W25Q_Status_BP0                                        0x04U
#define vI_W25Q_Status_BP1                                        0x08U
#define vI_W25Q_Status_BP2                                        0x10U
#define vI_W25Q_Status_TB                                         0x20U
#define vI_W25Q_Status_SEC                                        0x40U
//#define vI_W25Q_Status_                                        0x80U

//S8~S15
#define vI_W25Q_Status_SRL                                        0x01U
#define vI_W25Q_Status_QE                                         0x02U
//#define vI_W25Q_Status_                                        0x04U
#define vI_W25Q_Status_LB1                                        0x08U
#define vI_W25Q_Status_LB2                                        0x10U
#define vI_W25Q_Status_LB3                                        0x20U
#define vI_W25Q_Status_CMP                                        0x40U
#define vI_W25Q_Status_SUS                                        0x80U

//S16~S24
//#define vI_W25Q_Status_                                        0x01U
//#define vI_W25Q_Status_                                        0x02U
#define vI_W25Q_Status_WPS                                        0x04U
//#define vI_W25Q_Status_                                        0x08U
//#define vI_W25Q_Status_                                        0x10U
#define vI_W25Q_Status_DRV2                                       0x20U
#define vI_W25Q_Status_DRV1                                       0x40U
//#define vI_W25Q_Status_                                        0x80U




#define vI_W25Q_CMD_StatusREGWriteEnable                          0x50U

#define vI_W25Q_CMD_ReadREG_Status1                               0x05U
#define vI_W25Q_CMD_WriteREG_Status1                              0x01U

#define vI_W25Q_CMD_ReadREG_Status2                               0x35U
#define vI_W25Q_CMD_WriteREG_Status2                              0x31U

#define vI_W25Q_CMD_ReadREG_Status3                               0x15U
#define vI_W25Q_CMD_WriteREG_Status3                              0x11U


#define vI_W25Q_CMD_WriteEnable                                   0x06U
#define vI_W25Q_CMD_WriteDisable                                  0x04U

#define vI_W25Q_CMD_ReadData                                      0x03U
#define vI_W25Q_CMD_FastReadData                                  0x0BU
#define vI_W25Q_CMD_FastReadDualOutput                            0x3BU
#define vI_W25Q_CMD_FastReadDual_IO                               0xBBU
#define vI_W25Q_CMD_FastReadQuadOutput                            0x6BU
#define vI_W25Q_CMD_FastReadQuad_IO                               0xEBU

#define vI_W25Q_CMD_PageProgram                                   0x02U
#define vI_W25Q_CMD_QuadPageProgram                               0x32U

#define vI_W25Q_CMD_SectorErase                                   0x20U //4096字节擦除 4096字节对齐
#define vI_W25Q_CMD_32KBErase                                     0x52U //32字节擦除
#define vI_W25Q_CMD_64KBErase                                     0xD8U //64字节擦除
#define vI_W25Q_CMD_ChipErase                                     0xC7U //全片擦除

#define vI_W25Q_CMD_GetID                                         0x90U //获取id




#define cI_W25Q_8to16(cmd) ((unsigned short)(cmd)|((((unsigned short)(cmd))<<8)&0xFF00U))




static unsigned short GetStatus(unsigned char StatusRegAddr){
  unsigned short r;

  oI_W25Q_DualBank_BKCS_SetOutput_Low();
  TxRxByte(cI_W25Q_8to16(StatusRegAddr));
  r=TxRxByte(0xFFFFU);
  oI_W25Q_DualBank_BKCS_SetOutput_High();

  return r;
}

static void SetStatus(unsigned char StatusRegAddr,unsigned short Status){

  oI_W25Q_DualBank_BKCS_SetOutput_Low();
  TxRxByte(cI_W25Q_8to16(StatusRegAddr));
  TxRxByte(Status);
  oI_W25Q_DualBank_BKCS_SetOutput_High();
}

static void TransmitCMD(unsigned char CMD){

  oI_W25Q_DualBank_BKCS_SetOutput_Low();
  TxRxByte(cI_W25Q_8to16(CMD));
  oI_W25Q_DualBank_BKCS_SetOutput_High();
}

static void TransmitCMD_24BitAddr(unsigned char CMD,unsigned int Address){

  oI_W25Q_DualBank_BKCS_SetOutput_Low();
  TxRxByte(cI_W25Q_8to16(CMD));
  TxRxByte(cI_W25Q_8to16((unsigned char)(Address>>16)));
  TxRxByte(cI_W25Q_8to16((unsigned char)(Address>>8)));
  TxRxByte(cI_W25Q_8to16((unsigned char)Address));
  oI_W25Q_DualBank_BKCS_SetOutput_High();
}

// static void RegWriteEnable(){
//   TransmitCMD(vI_W25Q_CMD_StatusREGWriteEnable);
//   Delay50ns();
// }

static void WriteEnable(){
  TransmitCMD(vI_W25Q_CMD_WriteEnable);
  Delay50ns();
}




/**
 * @brief 初始化相关IO
 * @return 无
 */
void I_W25Q_DualBank_Init(){

  IO_Init();
}

/**
 * @brief 获取Flash ID
 * @return Flash ID
 */
unsigned int I_W25Q_DualBank_GetID(){
  unsigned int ID;
  unsigned short t;

  oI_W25Q_DualBank_BKCS_SetOutput_Low();
  TxRxByte(cI_W25Q_8to16(vI_W25Q_CMD_GetID));
  TxRxByte(0x0000U);
  TxRxByte(0x0000U);
  TxRxByte(0x0000U);
  t=TxRxByte(0xFFFFU);
  ID=(0xFF000000U&((unsigned int)t<<16))|(0x0000FF00U&((unsigned int)t<<8));
  t=TxRxByte(0xFFFFU);
  ID|=(0x00FF0000U&((unsigned int)t<<8))|(0x000000FFU&t);
  oI_W25Q_DualBank_BKCS_SetOutput_High();
  Delay50ns();

  return ID;
}

/**
 * @brief 获取状态寄存器的值
 * @return 状态值
 */
unsigned short I_W25Q_DualBank_GetStatusReg1(){
  unsigned short r;

  r=GetStatus(vI_W25Q_CMD_ReadREG_Status1);
  Delay50ns();
  return r;
}

/**
 * @brief 获取状态寄存器的值
 * @return 状态值
 */
unsigned short I_W25Q_DualBank_GetStatusReg2(){
  unsigned short r;

  r=GetStatus(vI_W25Q_CMD_ReadREG_Status2);
  Delay50ns();
  return r;
}

/**
 * @brief 获取状态寄存器的值
 * @return 状态值
 */
unsigned short I_W25Q_DualBank_GetStatusReg3(){
  unsigned short r;

  r=GetStatus(vI_W25Q_CMD_ReadREG_Status3);
  Delay50ns();
  return r;
}

void I_W25Q_DualBank_WaitBusy(){

  while((cI_W25Q_8to16(vI_W25Q_Status_BUSY)&I_W25Q_DualBank_GetStatusReg1())!=0U){
    //等待BUSY为0
  }
}

/**
 * @brief 获取Flash容量
 * @param Size1 将用于存放Flash1的容量
 * @param Size2 将用于存放Flash2的容量
 * @return 无
 */
void I_W25Q_DualBank_GetSize(unsigned int* Size1,unsigned int* Size2){

  unsigned int id;
  unsigned short id1,id2;

  id=I_W25Q_DualBank_GetID();
  id1=(unsigned short)(0x0000FFFFU&id);
  id2=(unsigned short)(0x0000FFFFU&(id>>16));

  if(id1==vI_W25Q_ID_80){
    Size1[0]=1024U*1024U;
  }else if(id1==vI_W25Q_ID_16){
    Size1[0]= 2U*1024U*1024U;
  }else if(id1==vI_W25Q_ID_32){
    Size1[0]= 4U*1024U*1024U;
  }else if(id1==vI_W25Q_ID_64){
    Size1[0]= 8U*1024U*1024U;
  }else if(id1==vI_W25Q_ID_128){
    Size1[0]= 16U*1024U*1024U;
  }else{
    Size1[0]= 0U;
  }

  if(id2==vI_W25Q_ID_80){
    Size2[0]= 1024U*1024U;
  }else if(id2==vI_W25Q_ID_16){
    Size2[0]= 2U*1024U*1024U;
  }else if(id2==vI_W25Q_ID_32){
    Size2[0]= 4U*1024U*1024U;
  }else if(id2==vI_W25Q_ID_64){
    Size2[0]= 8U*1024U*1024U;
  }else if(id2==vI_W25Q_ID_128){
    Size2[0]= 16U*1024U*1024U;
  }else{
    Size2[0]= 0U;
  }

}

/**
 * @brief 写状态寄存器
 * @param Value 状态寄存器的值
 * @return 无
 */
void I_W25Q_DualBank_SetStatusReg1(unsigned short Value){
  WriteEnable();
  SetStatus(vI_W25Q_CMD_WriteREG_Status1,Value);
  Delay50ns();
  I_W25Q_DualBank_WaitBusy();
}

/**
 * @brief 写状态寄存器
 * @param Value 状态寄存器的值
 * @return 无
 */
void I_W25Q_DualBank_SetStatusReg2(unsigned short Value){
  WriteEnable();
  SetStatus(vI_W25Q_CMD_WriteREG_Status2,Value);
  Delay50ns();
  I_W25Q_DualBank_WaitBusy();
}

/**
 * @brief 写状态寄存器
 * @param Value 状态寄存器的值
 * @return 无
 */
void I_W25Q_DualBank_SetStatusReg3(unsigned short Value){
  WriteEnable();
  SetStatus(vI_W25Q_CMD_WriteREG_Status3,Value);
  Delay50ns();
  I_W25Q_DualBank_WaitBusy();
}

/**
 * @brief 设置Flash为Quad模式
 * @return 无
 */
void I_W25Q_DualBank_SetQuad(){

  if((I_W25Q_DualBank_GetStatusReg2()&(cI_W25Q_8to16(vI_W25Q_Status_QE)))!=cI_W25Q_8to16(vI_W25Q_Status_QE)){//有不为QE模式
    I_W25Q_DualBank_SetStatusReg2(cI_W25Q_8to16(vI_W25Q_Status_QE));
  }

  if((I_W25Q_DualBank_GetStatusReg3()&(cI_W25Q_8to16(vI_W25Q_Status_DRV1|vI_W25Q_Status_DRV2)))!=0U){//DRV1 DRV2 不都为0
    I_W25Q_DualBank_SetStatusReg3(0U);
  }

}




//==============================================================================================================================
//
//       读写操作
//
//==============================================================================================================================

/**
 * @brief 读取数据 FastRead
 * @param DeviceAddress 器件读取起始地址 必须2字节对齐
 * @param Dst 指向用于容纳数据的缓冲区
 * @param Length 读取数据长度 必须为2的倍数
 * @return 无
 */
void I_W25Q_DualBank_ReadData(unsigned int DeviceAddress,unsigned char* Dst,int Length){
  unsigned char temp[8];

  
  DeviceAddress>>=1;//Flash地址

  temp[0]=(unsigned char)(DeviceAddress>>16);
  temp[2]=(unsigned char)(DeviceAddress>>8);
  temp[4]=(unsigned char)DeviceAddress;
  temp[6]=0xFFU;

  temp[1]=temp[0];
  temp[3]=temp[2];
  temp[5]=temp[4];
  temp[7]=temp[6];


  oI_W25Q_DualBank_BKCS_SetOutput_Low();
  TxRxByte(cI_W25Q_8to16(vI_W25Q_CMD_FastReadQuad_IO));
  oI_W25Q_DualBank_BKIO_OUT();
  Tx_4Line(temp,8);
  oI_W25Q_DualBank_BKIO_IN();
  Rx_4Line(temp,4);
  Rx_4Line(Dst,Length);
  oI_W25Q_DualBank_BKCS_SetOutput_High();
  Delay10ns();
  SetIO_1Line();
}

/**
 * @brief 读取数据 可不2字节对齐
 * @param DeviceAddress 器件读取起始地址
 * @param Dst 指向用于容纳数据的缓冲区
 * @param Length 读取数据长度
 * @return 无
 */
void I_W25Q_DualBank_ReadData_NoAlign(unsigned int DeviceAddress,unsigned char* Dst,int Length){
  unsigned int EndDeviceAddress;
  unsigned char Buffer[2];
  
  if((DeviceAddress&0x00000001U)!=0U){
    I_W25Q_DualBank_ReadData(DeviceAddress-1,Buffer,2);
    Dst[0]=Buffer[1];

    DeviceAddress+=1;
    Dst=&Dst[1];
    Length-=1;
  }
  EndDeviceAddress=DeviceAddress+Length;//读取的最后一个字节的后一个字节的位置
  if((EndDeviceAddress&0x00000001U)!=0U){
    I_W25Q_DualBank_ReadData(EndDeviceAddress-1,Buffer,2);
    Dst[Length-1]=Buffer[0];

    Length-=1;
  }

  I_W25Q_DualBank_ReadData(DeviceAddress,Dst,Length);
}

/**
 * @brief 写入数据 每次该方法只能写一页范围内的数据
 * @param DeviceAddress 器件读取起始地址 必须2字节对齐
 * @param Src 指向用于写入数据的数据
 * @param Length 写入数据的长度 必须为2的倍数
 * @return 无
 */
void I_W25Q_DualBank_PageProgram(unsigned int DeviceAddress,unsigned char* Src,int Length){

  DeviceAddress>>=1;

  WriteEnable();

  oI_W25Q_DualBank_BKCS_SetOutput_Low();
  TxRxByte(cI_W25Q_8to16(vI_W25Q_CMD_QuadPageProgram));
  TxRxByte(cI_W25Q_8to16((unsigned char)(DeviceAddress>>16)));
  TxRxByte(cI_W25Q_8to16((unsigned char)(DeviceAddress>>8)));
  TxRxByte(cI_W25Q_8to16((unsigned char)DeviceAddress));
  oI_W25Q_DualBank_BKIO_OUT();
  Tx_4Line(Src,Length);
  oI_W25Q_DualBank_BKCS_SetOutput_High();
  Delay50ns();
  SetIO_1Line();

  I_W25Q_DualBank_WaitBusy();
}

/**
 * @brief 擦除扇区 8KB
 * @param DeviceAddress 扇区地址
 * @return 无
 */
void I_W25Q_DualBank_Erase(unsigned int DeviceAddress){

  DeviceAddress>>=1;

  WriteEnable();
  TransmitCMD_24BitAddr(vI_W25Q_CMD_SectorErase,DeviceAddress);
  Delay50ns();
  I_W25Q_DualBank_WaitBusy();
}

/**
 * @brief 擦除扇区 64KB
 * @param DeviceAddress 扇区地址
 * @return 无
 */
void I_W25Q_DualBank_64KBErase(unsigned int DeviceAddress){

  DeviceAddress>>=1;

  WriteEnable();
  TransmitCMD_24BitAddr(vI_W25Q_CMD_32KBErase,DeviceAddress);
  Delay50ns();
  I_W25Q_DualBank_WaitBusy();
}

/**
 * @brief 擦除扇区 128KB
 * @param DeviceAddress 扇区地址
 * @return 无
 */
void I_W25Q_DualBank_128KBErase(unsigned int DeviceAddress){

  DeviceAddress>>=1;

  WriteEnable();
  TransmitCMD_24BitAddr(vI_W25Q_CMD_64KBErase,DeviceAddress);
  Delay50ns();
  I_W25Q_DualBank_WaitBusy();
}

/**
 * @brief 擦除扇区 整片擦除
 * @return 无
 */
void I_W25Q_DualBank_ChipErase(){

  WriteEnable();
  TransmitCMD(vI_W25Q_CMD_ChipErase);
  Delay50ns();
  I_W25Q_DualBank_WaitBusy();
}



